//
//  AddHomeView.m
//  location
//
//  Created by Dongxiang Xu on 2025/4/29.
//

#import "AddHomeView.h"

@implementation AddHomeView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
                
        UIImpactFeedbackGenerator *feedBackGenertor = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight];
        [feedBackGenertor impactOccurred];
        
        UIButton *bgButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.height)];
        [self addSubview:bgButton];
               
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-16, STATUSHEIGHT+49, 0, 0)];
        view.layer.masksToBounds = YES;
        [self addSubview:view];
        
        UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 136, 102)];
        img.userInteractionEnabled = YES;
        img.image = [UIImage imageNamed:@"add_home"];
        [view addSubview:img];
        
        [[bgButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            [UIView animateWithDuration:.3f animations:^{
                self.backgroundColor = [RealBlackColor colorWithAlphaComponent:0.0];
                img.alpha = 0;
            } completion:^(BOOL finished) {
                [self removeFromSuperview];
            }];
        }];
        
        for (int i = 0; i < 2; i ++) {
            UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, i*51, img.width, 51)];
            [img addSubview:button];
            [[button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
                if (self.AddHomeViewBlock) {
                    self.AddHomeViewBlock(i);
                }
                
                [UIView animateWithDuration:.3f animations:^{
                    self.backgroundColor = [RealBlackColor colorWithAlphaComponent:0.0];
                    img.alpha = 0;
                } completion:^(BOOL finished) {
                    [self removeFromSuperview];
                }];
            }];
        }
        
        [UIView animateWithDuration:.3f animations:^{
            self.backgroundColor = [RealBlackColor colorWithAlphaComponent:0.4];
            [view setFrame:CGRectMake(SCREEN_WIDTH-152, STATUSHEIGHT+49, 136, 102)];
        }];
    }
    return self;
}

@end
